package com.itheima.a01mymap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class A05_MapDemo5 {
    public static void main(String[] args) {
        //创建集合
        HashMap<Student, String> hm = new HashMap<>();

        //创建学生对象
        Student s1 = new Student("zhangsan", 23);
        Student s2 = new Student("lisi", 24);
        Student s3 = new Student("wangwu", 25);
        Student s4 = new Student("wangwu", 25);

        //添加元素
        hm.put(s1, "北京");
        hm.put(s2, "上海");
        hm.put(s3, "广州");
        hm.put(s4, "吉林");
        //遍历输出
        Set<Student> keys = hm.keySet();
        for (Student key : keys) {
            String value = hm.get(key);
            System.out.println(key + "--" + value);
        }

        System.out.println("-----------------------");

        Set<Map.Entry<Student, String>> entries = hm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }


        System.out.println("---------------------");
        //使用lambda表达式
        hm.forEach((Student student, String s) -> System.out.println(student + s));
    }
}
